﻿<UserControl x:Class="yavc.Phone.Controls.BrowsePageControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:conv="clr-namespace:yavc.Phone.Lib.Util;assembly=yavc.Phone.Lib"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}">
    <UserControl.Resources>
        <Style TargetType="Button" BasedOn="{StaticResource clearButtonStyle}">
            <Setter Property="Margin" Value="10" />
        </Style>
        <conv:VisibilityBooleanConverter x:Key="trueVisConv"
                                         DefaultVisibility="Collapsed" 
                                         FalseVisibility="Collapsed" 
                                         TrueVisibility="Visible" />
        <conv:InverterConverter x:Name="invConv" />
        <conv:ColorBooleanConverter x:Key="triangleConv" 
                                    DefaultColor="{StaticResource PhoneDisabledBrush}"
                                    FalseColor="{StaticResource PhoneDisabledBrush}"
                                    TrueColor="{StaticResource PhoneForegroundBrush}" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="10" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <toolkit:PerformanceProgressBar IsIndeterminate="True" Visibility="{Binding IsRefreshing, Converter={StaticResource trueVisConv}}" Grid.ColumnSpan="2" Height="10" />

        <StackPanel Grid.Column="1" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center">
            <Button Click="btnPageUpJump_Click" IsEnabled="{Binding CanPageUpJump}">
                <Grid>
                    <Polygon Fill="{Binding CanPageUpJump, Converter={StaticResource triangleConv}}">
                        <Polygon.Points>
                            <Point X="0" Y="42" />
                            <Point X="82" Y="42" />
                            <Point X="41" Y="0" />
                            <Point X="0" Y="42" />
                        </Polygon.Points>
                    </Polygon>
                    <TextBlock Text="5x" HorizontalAlignment="Center" VerticalAlignment="Bottom" Margin="0,0,0,1" FontWeight="Bold" 
                               Foreground="{StaticResource PhoneBackgroundBrush}" />
                </Grid>
            </Button>
            <Button Click="btnPageUp_Click" IsEnabled="{Binding CanPageUp}">
                <Polygon Fill="{Binding CanPageUp, Converter={StaticResource triangleConv}}">
                    <Polygon.Points>
                        <Point X="0" Y="42" />
                        <Point X="82" Y="42" />
                        <Point X="41" Y="0" />
                        <Point X="0" Y="42" />
                    </Polygon.Points>
                </Polygon>
            </Button>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                <TextBlock Text="(" />
                <TextBlock Text="{Binding CurrentPage}" />
                <TextBlock Text=" / " />
                <TextBlock Text="{Binding TotalPages}" />
                <TextBlock Text=")" />
            </StackPanel>
            <Button Click="btnPageDown_Click" IsEnabled="{Binding CanPageDown}">
                <Polygon Fill="{Binding CanPageDown, Converter={StaticResource triangleConv}}">
                    <Polygon.Points>
                        <Point X="0" Y="42" />
                        <Point X="82" Y="42" />
                        <Point X="41" Y="0" />
                        <Point X="0" Y="42" />
                    </Polygon.Points>
                    <Polygon.RenderTransform>
                        <RotateTransform Angle="180" CenterX="41" CenterY="21" />
                    </Polygon.RenderTransform>
                </Polygon>
            </Button>
            <Button Click="btnPageDownJump_Click" IsEnabled="{Binding CanPageDownJump}">
                <Grid>
                    <Polygon Fill="{Binding CanPageDownJump, Converter={StaticResource triangleConv}}">
                        <Polygon.Points>
                            <Point X="0" Y="42" />
                            <Point X="82" Y="42" />
                            <Point X="41" Y="0" />
                            <Point X="0" Y="42" />
                        </Polygon.Points>
                        <Polygon.RenderTransform>
                            <RotateTransform Angle="180" CenterX="41" CenterY="21" />
                        </Polygon.RenderTransform>
                    </Polygon>
                    <TextBlock Text="5x" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,-2,0,0" FontWeight="Bold" 
                               Foreground="{StaticResource PhoneBackgroundBrush}" />
                </Grid>
            </Button>
        </StackPanel>

        <ItemsControl Grid.Row="1"
                      ItemsSource="{Binding Items}"  
                      IsEnabled="{Binding IsRefreshing, Converter={StaticResource invConv}}">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Content="{Binding Text}" Click="btnItem_Click" HorizontalContentAlignment="Left" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Grid>
</UserControl>
